package com.qf.mapper;

import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayCountStatis;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.qf.vo.OrderStatVo;

import java.util.List;
import java.util.Map;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
public interface StatMapper {
    List<CategorySellAmts> findCategoryShellData();

    List<DayStatis> queryUserStatis(int rang);

    List<DayStatis> queryOrderStatis(int rang);

    List<OrderStatVo>findOrderStat(int rang);


    @Select("SELECT  DATE_FORMAT(add_time,'%Y-%m-%d') AS day,COUNT(1) AS users FROM dts_user " +
            "WHERE add_time > DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'),INTERVAL #{day} DAY)  GROUP BY day;")
    List<DayCountStatis> findUserCount(int day);

    //一个月每天订单量和订单总额和日期
    @Select("SELECT DATE_FORMAT(add_time,'%Y-%m-%d') AS dayStr,SUM(order_price) AS amts," +
            "COUNT(1) AS cnts FROM dts_order WHERE order_status NOT IN (101,102,103)" +
            " AND deleted = 0 AND add_time > DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d')," +
            "INTERVAL #{day} DAY)  GROUP BY dayStr;")
    List<DayStatis> findOrderAmts(int day);

    @Update("update dts_admin set password = #{newPwd} where id = #{id}")
    void updateAdminPwd(@Param("newPwd") String newPwd, @Param("id") Integer id);
}
